using ASP;
using HoWave.Web;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Shop_Auction_shop_request_productEdit : Shop, IRequiresSessionState
{
	public static int RequestID = 0;
	protected Label ClassName;
	protected Literal setclass;
	protected HiddenField ClassID;
	protected TextBox p_name;
	protected RequiredFieldValidator rvf5;
	protected TextBox ProductDescripe;
	protected FileUpload FileUpload1;
	protected HiddenField H_ProductImg;
	protected Image ProductImg;
	protected TextBox p_num;
	protected RequiredFieldValidator rfv1;
	protected RangeValidator rv1;
	protected TextBox P_uint;
	protected RequiredFieldValidator rfv4;
	protected TextBox p_price;
	protected RequiredFieldValidator RequiredFieldValidator2;
	protected RangeValidator rv3;
	protected TextBox p_validay;
	protected RequiredFieldValidator RequiredFieldValidator3;
	protected RangeValidator RangeValidator2;
	protected Shop_UserControls_HowaveProvinceCity HowaveProvinceCity1;
	protected TextBox p_remark;
	protected Label err_tips;
	protected Button prev_Button;
	protected Button submit_btn;
	protected HiddenField H_ProductID;
	protected HtmlForm form1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
		try
		{
			Template.BindTemplateToPage(this.Page, "RequestProduct");
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message);
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		base.ShowCityArea();
		this.FileUpload1.Attributes.Add("onchange", "document.getElementById('previewImage').innerHTML ='预览<br><img src=\\''+this.value+'\\' width=100 height=100 onload=\\'ResizeImage(this, 100, 100);\\' align=absmiddle id=preview_img>';");
		if (!base.IsPostBack)
		{
			this.BandDataBase();
		}
	}
	protected void BandDataBase()
	{
		if (base.Request["RequestProductID"] != null && base.Request["RequestProductID"] != "")
		{
			Shop_Auction_shop_request_productEdit.RequestID = int.Parse(base.Request["RequestProductID"]);
			Shop_Request shop_Request = new Shop_Request();
			DataTable requestByID = shop_Request.GetRequestByID(Shop_Auction_shop_request_productEdit.RequestID);
			if (requestByID.Rows.Count > 0)
			{
				string text = requestByID.Rows[0]["UploadImageUrl"].ToString();
				this.H_ProductImg.Value = text;
				this.p_name.Text = requestByID.Rows[0]["RequestTitle"].ToString();
				this.ProductDescripe.Text = requestByID.Rows[0]["Description"].ToString();
				this.p_num.Text = requestByID.Rows[0]["RequestNumber"].ToString();
				this.p_price.Text = requestByID.Rows[0]["Price"].ToString();
				this.p_remark.Text = requestByID.Rows[0]["Remark"].ToString();
				this.P_uint.Text = requestByID.Rows[0]["Unit"].ToString();
				this.p_validay.Text = requestByID.Rows[0]["ValidDate"].ToString();
				this.ProductImg.ImageUrl = "UpLoadFile/ShopRequest/" + text;
				string text2 = requestByID.Rows[0]["RequestPlace"].ToString();
				int length = text2.Length;
				string selectedValue;
				string selectedValue2;
				if (text2.Contains("黑龙江") || text2.Contains("内蒙古"))
				{
					selectedValue = text2.Substring(0, 3);
					selectedValue2 = text2.Substring(3, length - 3);
				}
				else
				{
					selectedValue = text2.Substring(0, 2);
					selectedValue2 = text2.Substring(2, length - 2);
				}
				DropDownList dropDownList = (DropDownList)this.HowaveProvinceCity1.FindControl("Province");
				DropDownList dropDownList2 = (DropDownList)this.HowaveProvinceCity1.FindControl("City");
				dropDownList.SelectedValue = selectedValue;
				dropDownList2.SelectedValue = selectedValue2;
				if (!base.Request.UrlReferrer.ToString().Contains("ShopClassChoose.aspx"))
				{
					string text3 = "";
					int classID = int.Parse(requestByID.Rows[0]["RequestCategoryID"].ToString());
					this.ClassID.Value = classID.ToString();
					this.setclass.Text = " <script type=\"text/javascript\">setTimeout('setClassName(\\'" + this.ClassID.Value + "\\')',10);</script>";
					Shop_Class shop_Class = new Shop_Class();
					DataTable classByClassID = shop_Class.GetClassByClassID(classID);
					if (classByClassID.Rows.Count > 0)
					{
						text3 = text3 + classByClassID.Rows[0]["parentpath"].ToString() + "," + classID.ToString();
					}
					string[] array = text3.Split(new char[]
					{
						','
					});
					for (int i = 0; i < array.Length; i++)
					{
						if (array[i] != "")
						{
							DataTable classByClassID2 = shop_Class.GetClassByClassID(int.Parse(array[i]));
							if (classByClassID2.Rows.Count > 0)
							{
								Label expr_40D = this.ClassName;
								expr_40D.Text = expr_40D.Text + classByClassID2.Rows[0]["classname"].ToString() + "->";
							}
						}
					}
					if (this.ClassName.Text.Contains("->"))
					{
						this.ClassName.Text = this.ClassName.Text.Remove(this.ClassName.Text.Length - 2);
					}
				}
				else
				{
					this.ClassName.Text = base.Request["h_c_p_className"];
				}
			}
		}
	}
	protected void submit_btn_click(object sender, EventArgs e)
	{
		string text = this.P_uint.Text;
		string text2 = this.ProductDescripe.Text;
		string text3 = this.ClassID.Value.Trim();
		string text4 = this.p_name.Text;
		int productNumber = Convert.ToInt32(this.p_num.Text);
		decimal price = Convert.ToDecimal(this.p_price.Text);
		int validDay = Convert.ToInt32(this.p_validay.Text);
		DropDownList dropDownList = (DropDownList)this.HowaveProvinceCity1.FindControl("Province");
		DropDownList dropDownList2 = (DropDownList)this.HowaveProvinceCity1.FindControl("City");
		if (dropDownList2.SelectedValue == "" || dropDownList.SelectedValue == "")
		{
			this.err_tips.Text = "请选择地点";
		}
		else
		{
			string place = dropDownList.SelectedValue + dropDownList2.SelectedValue;
			string text5 = this.p_remark.Text;
			int userID = base.user.UserID;
			int productClassID = Convert.ToInt32(this.ClassID.Value);
			int enableRequest = 1;
			string text6 = this.UploadPhoto();
			if (text6 == "")
			{
				text6 = this.H_ProductImg.Value;
			}
			Shop_Request shop_Request = new Shop_Request();
			if (shop_Request.UpdateRequest(text4, productClassID, text2, text6, place, price, validDay, text5, productNumber, 1, enableRequest, text, Shop_Auction_shop_request_productEdit.RequestID))
			{
				this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert(\"提交成功\");window.location.href='../Member/Shop_Request.aspx'</script>");
			}
			else
			{
				this.err_tips.Text = "提交失败";
			}
		}
	}
	protected string UploadPhoto()
	{
		UpLoadFile upLoadFile = new UpLoadFile();
		upLoadFile.SaveInFoder = "/UploadFile/ShopRequest/";
		string text = "/UpLoadFile/ShopRequest/" + this.H_ProductImg.Value;
		if (text == "/UpLoadFile/ShopRequest/")
		{
			text = "";
		}
		return upLoadFile.UploadPic(this.FileUpload1, this.config, text);
	}
}
